import { request } from 'umi';
import {
  MaterialUsagePlanDto,
  MaterialUsagePlanPageResponse,
  MaterialPlanAddDto,
  MaterialUsagePlanDetailsVo
} from '@/services/materialUsagePlan/typings';

/**
 * 分页查询用料计划列表
 * @param body 查询参数
 * @param options 请求配置
 * @returns 分页查询结果
 */
export async function listMaterialUsagePlanVoByPage(
  body: RequestParam<MaterialUsagePlanDto>,
  options?: { [key: string]: any },
) {
  return request<MaterialUsagePlanPageResponse>('/api/materialUsagePlan/list', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/**
 * 添加用料计划
 * @param body 添加用料计划的请求体
 * @param options 请求配置
 * @returns 添加结果
 */
export async function addMaterialUsagePlan(
  body: MaterialPlanAddDto,
  options?: { [key: string]: any },
) {
  return request<BaseResponse<boolean>>('/api/materialUsagePlan/add', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/**
 * 根据 ID 获取用料计划详细信息
 * @param params 请求参数，包含用料计划 ID
 * @param options 请求配置
 * @returns 用料计划详细信息
 */
export async function getMaterialUsagePlanDetailsById(
  params: { id: string },
  options?: { [key: string]: any },
) {
  return request<BaseResponse<MaterialUsagePlanDetailsVo>>('/api/materialUsagePlan/', {
    method: 'GET',
    params: params,
    ...(options || {}),
  });
}

/**
 * 审批用料计划
 * @param body 审批请求体，包含用料计划 ID
 * @param options 请求配置
 * @returns 审批结果
 */
export async function approvalMaterialUsagePlan(
  id: string,
  options?: { [key: string]: any },
) {
  return request<BaseResponse<boolean>>('/api/materialUsagePlan/approval', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: {
      data: id,
    },
    ...(options || {}),
  });
}
